package erfgame.core;

public class Range<Type> {

	protected Type min;
	protected Type max;
	
	public Range( Type min, Type max ) {
		this.min = min;
		this.max = max;
	}

	public Type getMin() {
		return min;
	}
	
	public Type getMax() {
		return max;
	}
	
	public static class Double extends Range<java.lang.Double> {
		
		private double diff;
		
		public Double( java.lang.Double extent ) {
			this( -extent, extent );
		}
		
		public Double( java.lang.Double min, java.lang.Double max ) {
			super( min, max );
			this.diff = max - min;
		}
	
		/**
		 * Obtains a value in the range 
		 * @param proportion a number between -1 and 1 
		 * @return a value between min and max proportional to the parameter
		 */
		public double getValue( double proportion ) {
			return min + (diff * proportion);
		}
	}
	
	public static class Integer extends Range<java.lang.Integer> {
		private int diff;
		
		public Integer( java.lang.Integer min, java.lang.Integer max ) {
			super( min, max );
			this.diff = max - min;
		}
		
		public int getValue( double proportion ) {
			return min + (int)Math.round(diff * proportion);
		}
	}
}
